const fs = require('fs')
const path = require('path')
function filterFiles(dir, ext, recur = true) {
    let files = [];

    let temp = fs.readdirSync(dir);
    temp.forEach(_f => {
        let _stat = fs.statSync(dir + path.sep + _f);
        if (_stat.isDirectory()) {
            files.push(...filterFiles(dir + path.sep + _f, ext, recur));
        } else {
            if (!ext || _f.endsWith(ext)) {
                files.push(dir + path.sep + _f);
            }
        }
    })
    return files;
}

function readPrefab(file) {
    let content = fs.readFileSync(file);
    return JSON.parse(content);
}

module.exports = {
    filterFiles,
    readPrefab
}